"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProperty = getProperty;
exports.setProperty = setProperty;
exports.setProperties = setProperties;
function getProperty(entities, propertyName = 'id', pipe) {
    const ids = entities.map(value => {
        let element = value[propertyName];
        if (pipe) {
            element = pipe(element);
        }
        return element;
    }).filter(Boolean);
    return [...new Set(ids)];
}
function setProperty(entities, dbEntities, match, set, notFoundProcess, moreMatchAndSet = []) {
    function process(entity, index, match, set) {
        const dbEntity = dbEntities.find(dbEntity => match(dbEntity, entity));
        if (dbEntity) {
            const r = set(dbEntity, entity);
            if (r) {
                entities[index] = r;
            }
        }
        else if (notFoundProcess) {
            notFoundProcess(entity);
        }
    }
    for (let i = 0; i < entities.length; i++) {
        let entity = entities[i];
        process(entity, i, match, set);
        if (moreMatchAndSet?.length > 0) {
            for (let { match, set } of moreMatchAndSet) {
                process(entity, i, match, set);
            }
        }
    }
}
function setProperties(entities, dbEntities, match, set) {
    for (let entity of entities) {
        const filter = dbEntities.filter(dbEntity => match(dbEntity, entity));
        set(filter, entity);
    }
}
